package tx.bj12320.util;

import java.net.URL;


public class AppHelper {
	private AppHelper() {
	}


	public static String getWebAppPath() {
		AppHelper util = new AppHelper();

		String clazzFilePath = util.getClassFilePath();
		String webPath = clazzFilePath.substring(0, clazzFilePath
				.indexOf("WEB-INF"));
		return webPath;

	}

	private String getClassFilePath() {
		String strClassName = getClass().getName();
		String strPackageName = "";
		if (getClass().getPackage() != null) {
			strPackageName = getClass().getPackage().getName();
		}
		String strClassFileName = "";
		if (!"".equals(strPackageName)) {
			strClassFileName = strClassName.substring(
					strPackageName.length() + 1, strClassName.length());
		} else {
			strClassFileName = strClassName;
		}
		URL url = null;
		url = getClass().getResource(strClassFileName + ".class");

		String strURL = url.getFile();
		try {
			strURL = java.net.URLDecoder.decode(strURL, "UTF-8");
		} catch (Exception ex) {
			ex.printStackTrace();
		}
		/*strURL = strURL.substring(strURL.indexOf('/') + 1,
		 strURL.lastIndexOf('/'))*/;

		return strURL;
	}

	public static void main(String[] args) {
		System.out.println(AppHelper.getWebAppPath());
	}


}
